package concurrency.tij;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import util.DaemonThreadFactory;

public class DaemonFromFactory implements Runnable {

	public void run() {
		try{
			while(true){
				TimeUnit.MILLISECONDS.sleep(100);
				System.out.println(Thread.currentThread());
			}
		}catch(InterruptedException e){
			e.printStackTrace();
		}
	}

	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		ExecutorService exe = Executors.newCachedThreadPool(new DaemonThreadFactory());
		
		for(int i = 0; i < 10; i++){
			exe.execute(new DaemonFromFactory());
		}
		
		System.out.println("All threads started...");
		TimeUnit.MILLISECONDS.sleep(700);
		System.out.println("All threads finished...");
	}

}
